﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EmployeeManager.DataAccess;
using System.Data.SqlClient;
//using EmployeeManager.Controller;

namespace EmployeeManager.View
{
    public partial class FormChitiet : Form
    {
        public FormChitiet()
        {
            InitializeComponent();
        }
        NhanvienAccess ac = new NhanvienAccess();
        SqlDataAdapter da = new SqlDataAdapter();
        DataTable dt = new DataTable("NHANSU");
        public SqlConnection getconnect()
        {
            return new SqlConnection(@"Server = TOETCAO-PC;Database = QLNHANSU_BTL; Integrated Security=SSPI;");

        }
        private void buttSua_Click(object sender, EventArgs e)
        {
            SqlConnection con = getconnect();
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
             cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "update_NHANSU";
            cmd.Parameters.Add("@MANV", SqlDbType.Char).Value = txtManhanvien.Text;
            cmd.Parameters.Add("@TENNV", SqlDbType.NVarChar).Value = txtHovaten.Text;
            cmd.Parameters.Add("@NGAYSINH", SqlDbType.DateTime).Value = txtNgaysinh.Text;
            cmd.Parameters.Add("@GIOITINH", SqlDbType.Char, 3).Value = txtGioitinh.Text;
            cmd.Parameters.Add("@NOISINH", SqlDbType.NVarChar, 50).Value = txtNoisinh.Text;
            cmd.Parameters.Add("@TONGIAO", SqlDbType.NVarChar, 20).Value = txtTongiao.Text;
            cmd.Parameters.Add("@QUOCTICH", SqlDbType.NVarChar, 20).Value = txtQuoctich.Text;
            cmd.Parameters.Add("@SoCMND", SqlDbType.Char, 20).Value = txtSocmnd.Text;
            cmd.Parameters.Add("@NoiCapCMND", SqlDbType.NVarChar, 50).Value = txtNoicap.Text;
            cmd.Parameters.Add("@NgayCapCMND", SqlDbType.DateTime).Value = txtNgaycap.Text;
            cmd.Parameters.Add("@DIACHIHIENTAI", SqlDbType.NVarChar, 50).Value = txtDiachi.Text;
            cmd.Parameters.Add("@SODIENTHOAI", SqlDbType.Char, 20).Value = txtSodienthoai.Text;
            cmd.Parameters.Add("@EMAIL", SqlDbType.NVarChar, 50).Value = txtEmail.Text;
            cmd.ExecuteNonQuery();
            da.SelectCommand = cmd;
               if (MessageBox.Show("Bạn có muốn sửa tên phòng" + txtHovaten.Text + " không ?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                   MessageBox.Show("update Successed!");
               FormChitiet_Load(sender, e);
         
        }

        private void buttThem_Click(object sender, EventArgs e)
        {
            SqlConnection con = getconnect();
            con.Open();
            SqlCommand cmd = new SqlCommand();
            //SqlCommand cmd = new SqlCommand("insert_NHANSU", con);
            cmd.Connection = con;
            
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "insert_NHANSU";
            cmd.Parameters.Add("@MANV", SqlDbType.Char).Value = txtManhanvien.Text;
            //cmd.Parameters.Add("@HODEM", SqlDbType.NVarChar,).Value = txtHovaten.Text;
            cmd.Parameters.Add("@TENNV",SqlDbType.NVarChar).Value=txtHovaten.Text;
            cmd.Parameters.Add("@NGAYSINH", SqlDbType.DateTime).Value = txtNgaysinh.Text;
            cmd.Parameters.Add("@GIOITINH", SqlDbType.Char,3).Value = txtGioitinh.Text;
            cmd.Parameters.Add("@NOISINH", SqlDbType.NVarChar,50).Value = txtNoisinh.Text;
            cmd.Parameters.Add("@TONGIAO", SqlDbType.NVarChar,20).Value = txtTongiao.Text;
            cmd.Parameters.Add("@QUOCTICH", SqlDbType.NVarChar,20).Value = txtQuoctich.Text;
            cmd.Parameters.Add("@SoCMND", SqlDbType.Char,20).Value = txtSocmnd.Text;
            cmd.Parameters.Add("@NoiCapCMND", SqlDbType.NVarChar,50).Value = txtNoicap.Text;
            cmd.Parameters.Add("@NgayCapCMND", SqlDbType.DateTime).Value = txtNgaycap.Text;
            cmd.Parameters.Add("@DIACHIHIENTAI", SqlDbType.NVarChar,50).Value = txtDiachi.Text;
            cmd.Parameters.Add("@SODIENTHOAI", SqlDbType.Char,20).Value = txtSodienthoai.Text;
            cmd.Parameters.Add("@EMAIL", SqlDbType.NVarChar,50).Value = txtEmail.Text;
            cmd.ExecuteNonQuery();
            da.SelectCommand = cmd;
            //da.Fill(dt);

            if (MessageBox.Show("Bạn có muốn thêm không?", "thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                MessageBox.Show("Insert Successed!");
            FormChitiet_Load(sender, e);
        }

        private void FormChitiet_Load(object sender, EventArgs e)
        {
            
            
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            FormChinh fm = new FormChinh();
            fm.Show();
            this.Hide();
        }

        private void buttXoa_Click(object sender, EventArgs e)
        {
            SqlConnection con = getconnect();
            con.Open();
            SqlCommand cmd = new SqlCommand("delete_NHANVIEN", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@MANV", txtManhanvien.Text));
            cmd.ExecuteNonQuery();
            if (MessageBox.Show("Bạn có chắc chắn xóa nhân viên '" + MANV + "' ?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.No)
                return;
            con.Close();
        }





    }
}
